package net.frankish.moviebank2.front.model;

import java.util.Vector;

import javax.swing.JTable;
import javax.swing.event.RowSorterEvent;
import javax.swing.event.RowSorterListener;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import net.frankish.moviebank.beans.Movie;

public class MovieTable extends JTable {

	private static final long serialVersionUID = 1L;
	private Vector<Movie> movies = null;
	
	private int sortingState = 0;
	
	public MovieTable(Vector<Movie> movies) {
		super();
		this.movies = movies;
		this.setModel(new MovieListTableModel(this.movies));
		this.getColumnModel().getColumn(2).setMaxWidth(100);
		this.getColumnModel().getColumn(2).setMinWidth(100);
		MovieTableSortHandler handler = new MovieTableSortHandler(this.getTableHeader().getDefaultRenderer());
		this.getTableHeader().setDefaultRenderer(handler);
		this.setRowSorter(new TableRowSorter<TableModel>(this.getModel()));
		this.getRowSorter().addRowSorterListener(new RowSorterListener() {
			
			@Override
			public void sorterChanged(RowSorterEvent e) {
				System.out.println("Sorter Changed: "+e);				
			}
		});
	}
}
